<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    var myobj = {
        "床品件套": "床品件套",
        "居家生活": {
            "被枕褥毯": "被枕褥毯,床品件套"
        }

    };


    var dataObj = {
        "居家生活": {
            "床品件套": "床品件套",
            "被枕褥毯": "被枕盖毯,床垫床褥",
            "办公家具": "办公家具,好物精选",
            "卧室家具": "卧室家具,灯具,小件家具,北欧原木,浴室用品",
            "厨房电器": "厨房电器,餐厨爆款清单",
            "锅具清洁": "品质锅具,餐厨配件,刀剪砧板,餐具,水具杯壶,茶咖酒具,品茗茶具"

        },
        "宠物生活": {
            "宠物主粮": "猫粮,犬粮",
            "宠物零食": "宠物罐头,冻干零食"
        }
    }
    console.log(typeof(dataObj['居家生活']));;
    // 写一个获取json对象KEY值的函数，以数组形式返回
    function getkey(obj) {
        let arr = [];
        for (x in obj) {
            console.log(x);
            arr.push(x);
        }
        return arr;
    }
    console.log(getkey(dataObj['居家生活']));;
    // 获取对象的value,以二维数组形式返回
    function getvalue(obj) {
        let arr = [];
        for (x in obj) {
            console.log(obj[x]);
            arr.push(obj[x].split(','));

        }
        return arr;
    }
    console.log(getvalue(dataObj['居家生活']));;
    // 获取最大数量进行传参，建html结构
    function getKeyNum(obj) {
        let num = 0;
        for (x in obj) {
            num++;
        }
        return num;
    }
    console.log(getKeyNum(dataObj['居家生活']));
    // 字符串切割为数组


    getvalue(dataObj['居家生活']) //是个数组
        //二维数组
    console.log("***********");
    var arr1 = [1, 2, 3];
    var arr2 = [];
    var arr3 = [2, 3, 4];
    arr2.push(arr1);
    arr2.push(arr3);
    console.log(arr2);
</script>